package tech.aichan.AiQA.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author mengyu
 * @date 2024/03/03 9:31
 * 日志AOP
 */
@Component
@Aspect
@Slf4j
public class LogAspect {
    @Pointcut("execution(* com.temp.springbootinit.controller.*.*(..))")
    private void needLog(){}

    @Before("needLog()")
    public void addLog(JoinPoint joinPoint){
        // 方法名
        String methodName = joinPoint.getSignature().getName();
        // 类名
        String className = joinPoint.getSignature().getDeclaringType().getSimpleName();
        // 方法参数
        Object[] args = joinPoint.getArgs();
        log.info(className+"."+methodName+":{}", Arrays.toString(args));
    }
}
